package com.jimet.objects;

public class XMLCoder {
	
	private static String amp = "&";
	private static String lt = "<";
	private static String gt = ">";
	private static String quot = "\"";
	private static String apos = "'";
	
	public static String hidden = "hidden";
	public static String text = "text";
	public static String select = "select";
	public static String multiple = "multiple";
	public static String checkbox = "checkbox";
	
	public static String EncodeXML(String strParam){
		String tmpRet = strParam;
		tmpRet = tmpRet.replaceAll(amp,"&amp;");
		tmpRet = tmpRet.replaceAll(lt,"&lt;");
		tmpRet = tmpRet.replaceAll(gt,"&gt;");
		tmpRet = tmpRet.replaceAll(quot,"&quot;");
		tmpRet = tmpRet.replaceAll(apos,"&apos;");
		return tmpRet;
	}
	
	public static String DecodeXML(String strParam){
		String tmpRet = strParam;
		tmpRet = tmpRet.replaceAll("&amp;",amp);
		tmpRet = tmpRet.replaceAll("&lt;",lt);
		tmpRet = tmpRet.replaceAll("&gt;",gt);
		tmpRet = tmpRet.replaceAll("&quot;",quot);
		tmpRet = tmpRet.replaceAll("&apos;",apos);
		return tmpRet;		
	}
	
	public static String GenerateXMLItem(String strName, String strType, String strValue, String strOption)
	{
		String XMLline = "";
		
		XMLline  = "<item ";
		XMLline += " name=\"";
		XMLline += EncodeXML(strName)+"\" ";
		XMLline += " type=\"";
		XMLline += EncodeXML(strType)+"\" ";
		XMLline += " value=\"";
		XMLline += EncodeXML(strValue)+"\" ";
		XMLline += " option=\"";
		XMLline += EncodeXML(strOption)+"\" ";
		XMLline += "></item>";
		return XMLline;
	}
	
	public static String GenerateXMLMultipleItem(String strName, String strValue)
	{
		String XMLline = "";
		
		XMLline  = "<multiple ";
		XMLline += " text=\"";
		XMLline += EncodeXML(strName)+"\" ";
		XMLline += " value=\"";
		XMLline += EncodeXML(strValue)+"\" ";
		XMLline += "></multiple>";
		return XMLline;
	}	
	public static String startXMLMultipleItem(String strName, String strType, String strValue, String strOption)
	{
		String XMLline = "";
		
		XMLline  = "<item ";
		XMLline += " name=\"";
		XMLline += EncodeXML(strName)+"\" ";
		XMLline += " type=\"";
		XMLline += EncodeXML(strType)+"\" ";
		XMLline += " value=\"";
		XMLline += EncodeXML(strValue)+"\" ";
		XMLline += " option=\"";
		XMLline += EncodeXML(strOption)+"\" ";
		XMLline += ">";
		return XMLline;
	}
	
	public static String endXMLMultipleItem()
	{
		String XMLline = "";
		
		XMLline += "</item>";
		return XMLline;
	}		
}
